package com.mbmed.doctor.medadvice.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.mbmed.doctor.commons.mapper.ModelVo;
import com.mbmed.doctor.medadvice.bo.SysparametersBo;
import com.mbmed.doctor.medadvice.mapper.Bbx1;
import com.mbmed.doctor.medadvice.mapper.Sysparameters;

@Path("/sysparameters")
@Component
public class SysparametersService {

	private static Logger logger = Logger.getLogger(SysparametersService.class);
	
	@Autowired
	private SysparametersBo sysparametersbo;
	
	@Context
	Request request;
	
	
	
	/**
     * 检索检测页面权限控制
     * @param id 与数据库中主键对应的值
     * @return type :  返回查询操作所有符合条件的记录的VO对象，操作失败返回null
     * @throws Exception
     */
	@GET
	@Path("/getadivcejcsysparameters")
	@Produces({MediaType.APPLICATION_JSON})
    public ModelVo getAdivceJcSysparameters() throws Exception{
		ModelVo modelvo = new ModelVo();
		
		Sysparameters sysparameters = new Sysparameters();
		
		Map<String,Object> map = new HashMap<String,Object>();
	
		map.put("productid", "100");
		map.put("programid", "105003");
		map.put("paramno", "190");
		sysparameters = sysparametersbo.getAdivceJcSysparameters(map);
		Map<String,Object> remap = new HashMap<String,Object>();
		remap.put("190", sysparameters.getValue());
		map.put("paramno", "191");
		sysparameters = sysparametersbo.getAdivceJcSysparameters(map);
		remap.put("191", sysparameters.getValue());
		map.put("paramno", "192");
		sysparameters = sysparametersbo.getAdivceJcSysparameters(map);
		remap.put("192", sysparameters.getValue());
		map.put("paramno", "193");
		sysparameters = sysparametersbo.getAdivceJcSysparameters(map);
		remap.put("193", sysparameters.getValue());
		modelvo.setMap(remap);
    	return modelvo;
	}
	
	@GET
	@Path("/getsysparamvalue")
	@Produces({MediaType.APPLICATION_JSON})
	public ModelVo GetSysParamValue(
			@QueryParam("productid") java.lang.String productid,
			@QueryParam("programid") java.lang.String programid,
			@QueryParam("paramno") java.lang.String paramno
			)throws Exception{
		ModelVo modelVo = new ModelVo();
		
		if(null==productid||null==programid||null==paramno){
			modelVo.setResult("false");
			return modelVo;
		}
		
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("productid", Integer.parseInt(productid));
		map.put("programid", Integer.parseInt(programid));
		map.put("paramno", Integer.parseInt(paramno));
		
		Sysparameters sysparameters = new Sysparameters();
		sysparameters = sysparametersbo.getAdivceJcSysparameters(map);
		modelVo.setResult("success");
		modelVo.setResultMsg(sysparameters.getValue());
		return modelVo;
	}
	
	
	@GET
	@Path("/getftpsysparameters")
	@Produces({MediaType.APPLICATION_JSON})
	public ModelVo GetFtpSysParameters()throws Exception{
		ModelVo modelvo = new ModelVo();
		
		Sysparameters sysparameters = new Sysparameters();
		
		Map<String,Object> map = new HashMap<String,Object>();
	
		map.put("productid", "300");
		map.put("programid", "301004");
		map.put("paramno", "140");
		Map<String,Object> remap = new HashMap<String,Object>();
		sysparameters = sysparametersbo.getAdivceJcSysparameters(map);
		if (sysparameters != null){
			remap.put("140", sysparameters.getValue());
			map.put("paramno", "141");
			sysparameters = sysparametersbo.getAdivceJcSysparameters(map);
			remap.put("141", sysparameters.getValue());
			map.put("paramno", "142");
			sysparameters = sysparametersbo.getAdivceJcSysparameters(map);
			remap.put("142", sysparameters.getValue());
			map.put("paramno", "143");
			sysparameters = sysparametersbo.getAdivceJcSysparameters(map);
			remap.put("143", sysparameters.getValue());
		} else {
			remap.put("140", -1);
			remap.put("141", -1);
			remap.put("142", -1);
			remap.put("143", -1);
		}
		modelvo.setMap(remap);
    	return modelvo;
	}
	
	
	
}
